<template xmlns="http://www.w3.org/1999/html">
  <sea-data-table ref="tableObject" url="/notice/page" :on-action="onAction">
    <!--表头-->
    <sea-table-header slot="header">
      <!--标题栏-->
      <sea-table-title slot="title" title="消息模版" subtitle="消息会与业务代码产生耦合，一般需要禁用删除功能，只允许修改。"></sea-table-title>

      <!--按钮栏-->
      <template slot="buttons">
        <el-button plain size="small" title="新增" icon="fa fa-plus" @click="onAction('new')"></el-button>
      </template>
    </sea-table-header>

    <!--表头-->
    <template slot="columns">
      <el-table-column property="title" label="名称" width="180"></el-table-column>
      <el-table-column property="url" label="详情页" width="260"></el-table-column>
      <el-table-column property="disabled" label="禁用" width="120"></el-table-column>
      <el-table-column property="description" label="描述"></el-table-column>
      <el-table-column property="gmtCreate" label="创建时间" width="180"></el-table-column>
      <el-table-column property="gmtModified" label="修改时间" width="180"></el-table-column>

      <!--操作栏-->
      <sea-table-actionbar width="180" :on-action="onAction" :buttons="buttons"></sea-table-actionbar>
    </template>


    <!-- 弹窗、抽屉 -->
    <template slot="drawer">
      <sea-dialog ref="modify_dialog">
        <modify ref="modify" :on-succeed="onSucceed"></modify>
      </sea-dialog>
    </template>
  </sea-data-table>
</template>

<script>
import modify from "./modify";

export default {
    components: {modify},
    data() {
        return {
            // 操作名称
            operation: undefined
            // 当前操作的行级对象
            , row_data: undefined
            // 消息ID
            , msg_id: undefined
            // 操作栏
            , buttons: [
                {evt: 'edit', type: 'btn', label: '编辑', title: '编辑当前行'}
                , {evt: 'remove', type: 'btn', label: '删除', style: 'text-danger', title: '删除当前行'}
            ]
            // end--
        }
    },
    methods: {
        /**
         * 操作成功回调
         */
        onSucceed: function () {
            this.$refs.tableObject.reload();
        },
        /**
         * 操作栏事件分发
         * @param evt 事件
         * @param row 行级对象
         * @param old 可供回滚的参数
         */
        onAction: function (evt, row, old) {
            this.operation = evt;
            if (evt === 'edit') {
                let dialog = {title: `更新 - ${row.name}`, fullscreen: true};
                this.$refs.modify_dialog.open(dialog).then(() => {
                    this.row_data = row;
                    this.msg_id = row.msgId;
                    console.log(row);
                });
            } else if (evt === 'new') {
                let dialog = {title: '新建', fullscreen: true};
                this.$refs.modify_dialog.open(dialog).then(() => {
                    this.row_data = row;
                });
            }
        }
    }
}
</script>
